package com.zj.core.ui

import android.content.Context
import android.support.constraint.ConstraintLayout
import android.view.Gravity
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.zj.core.R
import org.jetbrains.anko.*
import org.jetbrains.anko.constraint.layout.constraintLayout
import org.jetbrains.anko.constraint.layout.guideline

class AboutActivityUi(groupView: LinearLayout):AnkoComponent<Context>{
    private var view: LinearLayout=groupView
    lateinit var version_text_view:TextView
    lateinit var version_update_tv:TextView
    lateinit var voice_template_tv:TextView
    lateinit var imei_tv:TextView

    override fun createView(ui: AnkoContext<Context>): View= with(view){
        constraintLayout {
            lparams(width= matchParent,height= matchParent)

            guideline{
                id=R.id.guideline_v_30
            }.lparams(width= wrapContent,height= matchParent){
                orientation=ConstraintLayout.LayoutParams.VERTICAL
                guidePercent=0.3F
            }

            guideline{
                id=R.id.guideline_v_70
            }.lparams(width= wrapContent,height= matchParent){
                orientation=ConstraintLayout.LayoutParams.VERTICAL
                guidePercent=0.7F
            }

            guideline{
                id=R.id.guideline_h_05
            }.lparams(width= matchParent,height= wrapContent){
                orientation=ConstraintLayout.LayoutParams.HORIZONTAL
                guidePercent=0.05F
            }

            guideline{
                id=R.id.guideline_h_30
            }.lparams(width= matchParent,height= wrapContent){
                orientation=ConstraintLayout.LayoutParams.HORIZONTAL
                guidePercent=0.3F
            }

            guideline{
                id=R.id.guideline_h_40
            }.lparams(width= matchParent,height= wrapContent){
                orientation=ConstraintLayout.LayoutParams.HORIZONTAL
                guidePercent=0.4F
            }

            imageView {
                scaleType= ImageView.ScaleType.CENTER_INSIDE
                backgroundResource=R.mipmap.logo
            }.lparams(width=0,height = 0){
                topToBottom=R.id.guideline_h_05
                bottomToTop=R.id.guideline_h_30
                leftToRight=R.id.guideline_v_30
                rightToLeft=R.id.guideline_v_70
            }

            /**
             * 软件名称
             */
            linearLayout {
                orientation=LinearLayout.HORIZONTAL
                id=R.id.app_name_lv
                textView {
                    text="软件名称"
                    gravity=Gravity.CENTER+Gravity.BOTTOM
                    textColor=context.resources.getColor(R.color.colorsGray)
                }.lparams(width= wrapContent,height = matchParent)

                textView().lparams(width= 0,height = matchParent){
                    weight=1F
                }

                textView {
                    text="子杰临床护理数据采集系统"
                    gravity=Gravity.CENTER+Gravity.BOTTOM
                    textColor=context.resources.getColor(R.color.colorsGray)
                }.lparams(width= wrapContent,height = matchParent)
            }.lparams(width = matchParent,height = dip(50)){
                setMargins(dip(20),0,dip(20),0)
                setPadding(0,0,0,dip(8))
                topToBottom=R.id.guideline_h_40
            }

            view {
                id=R.id.line1
                backgroundColor=context.resources.getColor(R.color.colorsFrenchGrey)
            }.lparams(width= matchParent,height=dip(1)){
                setMargins(dip(20),0,dip(20),0)
                topToBottom=R.id.app_name_lv
                bottomToTop=R.id.app_version_lv
            }

            /**
             * 版本号
             */
            linearLayout {
                orientation=LinearLayout.HORIZONTAL
                id=R.id.app_version_lv
                textView {
                    text="版本号"
                    gravity=Gravity.CENTER+Gravity.BOTTOM
                    textColor=context.resources.getColor(R.color.colorsGray)
                }.lparams(width= wrapContent,height = matchParent)

                textView().lparams(width= 0,height = matchParent){
                    weight=1F
                }

                version_text_view=textView {
                    id=R.id.version_text_view
                    text="V1.0"
                    gravity=Gravity.CENTER+Gravity.BOTTOM
                    textColor=context.resources.getColor(R.color.colorsGray)
                }.lparams(width= wrapContent,height = matchParent)
            }.lparams(width = matchParent,height = dip(50)){
                setMargins(dip(20),0,dip(20),0)
                setPadding(0,0,0,dip(8))
                topToBottom=R.id.line1
            }

            view {
                id=R.id.imei_code
                backgroundColor=context.resources.getColor(R.color.colorsFrenchGrey)
            }.lparams(width= matchParent,height=dip(1)){
                setMargins(dip(20),0,dip(20),0)
                topToBottom=R.id.app_version_lv
            }

            /**
             * 设备IMEI
             */
            linearLayout {
                orientation=LinearLayout.HORIZONTAL
                id=R.id.imei_lly
                textView {
                    text="设备IMEI"
                    gravity=Gravity.CENTER+Gravity.BOTTOM
                    textColor=context.resources.getColor(R.color.colorsGray)
                }.lparams(width= wrapContent,height = matchParent)

                textView().lparams(width= 0,height = matchParent){
                    weight=1F
                }

                imei_tv=textView {
                    id=R.id.imei_tv
                    text="未获取到IMEI"
                    gravity=Gravity.CENTER+Gravity.BOTTOM
                    textColor=context.resources.getColor(R.color.colorsGray)
                }.lparams(width= wrapContent,height = matchParent)
            }.lparams(width = matchParent,height = dip(50)){
                setMargins(dip(20),0,dip(20),0)
                setPadding(0,0,0,dip(8))
                topToBottom=R.id.imei_code
            }

            view {
                id=R.id.imei_line
                backgroundColor=context.resources.getColor(R.color.colorsFrenchGrey)
            }.lparams(width= matchParent,height=dip(1)){
                setMargins(dip(20),0,dip(20),0)
                topToBottom=R.id.imei_lly
            }

            /**
             * 百度语音模型ID
             */
            linearLayout {
                orientation=LinearLayout.HORIZONTAL
                id=R.id.voice_lly
                textView {
                    text="语音ID"
                    gravity=Gravity.CENTER+Gravity.BOTTOM
                    textColor=context.resources.getColor(R.color.colorsGray)
                }.lparams(width= wrapContent,height = matchParent)

                textView().lparams(width= 0,height = matchParent){
                    weight=1F
                }

                voice_template_tv=textView {
                    id=R.id.voice_tv
                    gravity=Gravity.CENTER+Gravity.BOTTOM
                    textColor=context.resources.getColor(R.color.colorsGray)
                }.lparams(width= wrapContent,height = matchParent)
            }.lparams(width = matchParent,height = dip(50)){
                setMargins(dip(20),0,dip(20),0)
                setPadding(0,0,0,dip(8))
                topToBottom=R.id.imei_line
            }

            view {
                id=R.id.voice_line
                backgroundColor=context.resources.getColor(R.color.colorsFrenchGrey)
            }.lparams(width= matchParent,height=dip(1)){
                setMargins(dip(20),0,dip(20),0)
                topToBottom=R.id.voice_lly
            }

            /**
             * 更新时间
             */
            linearLayout {
                orientation=LinearLayout.HORIZONTAL
                id=R.id.contact_us
                textView {
                    text="更新时间"
                    gravity=Gravity.CENTER+Gravity.BOTTOM
                    textColor=context.resources.getColor(R.color.colorsGray)
                }.lparams(width= wrapContent,height = matchParent)

                textView().lparams(width= 0,height = matchParent){
                    weight=1F
                }

                version_update_tv=textView {
                    id=R.id.version_update_tv
                    text="13323392673"
                    gravity=Gravity.CENTER+Gravity.BOTTOM
                    textColor=context.resources.getColor(R.color.colorsGray)
                }.lparams(width= wrapContent,height = matchParent)
            }.lparams(width = matchParent,height = dip(50)){
                setMargins(dip(20),0,dip(20),0)
                setPadding(0,0,0,dip(8))
                topToBottom=R.id.voice_lly
            }
        }
    }
}